<template>
  <div class="vue-box sbot-fluid sbot">
    <div class="c-panel">
      <el-form :inline="true">
        <sa-item v-model="m.permissions" type="cascaderPanel" :options="options" name=""
          :props="{ multiple: true, value: 'id', label: 'name' }" />
        <sa-item name="" class="s-ok" br>
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'rent-server-menu',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      options: null
    }
  },
  created: function () {
    // 查询服务菜单
    this.getSm()
  },
  methods: {
    // 创建一个 默认Model
    createModel() {
      return {
        id: this.param.id,
        permissions: []
      }
    },
    // 查询服务及菜单
    getSm() {
      sa.ajax('/rent/menu/tree', { id: this.m.id }, function (res) {
        this.m.permissions = res.data.permissions
        this.options = res.data.bt
      }.bind(this), { type: 'get' })
    },
    // 提交数据
    ok: function () {
      // 验证 获取 m对象
      let m = this.m;
      sa.checkNull(m.id, '请确认租户');
      sa.checkNull(m.permissions, '请确认权限');
      sa.ajax('/rent/assist', sa.removeNull(m), function (res) {
        sa.alert('租户分配权限成功', function () {
          this.m = this.createModel();
          sa.closeModel();
          sa.currView().f5();
        }.bind(this));
      }.bind(this));
    },
  }
}
</script>

<style scoped></style>